package com.itheima.controller;

import com.github.pagehelper.Page;
import com.itheima.entity.PageResult;
import com.itheima.entity.Result;
import com.itheima.pojo.Blog;
import com.itheima.pojo.BlogSort;
import com.itheima.service.BlogService;
import com.itheima.service.BlogSortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/classify")
@CrossOrigin(allowCredentials="true", allowedHeaders="*", methods={RequestMethod.GET,RequestMethod.POST}, origins="*")
public class ClassifyController {

    @Autowired
    private BlogService blogService;
    @Autowired
    private BlogSortService blogSortService;
    /**
     * 根据分类id分页查询博客
     * @param uid
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping("/getArticleByBlogSortUid")
    public Result getArticleByBlogSortUid(@RequestParam("blogSortUid")String uid,@RequestParam("currentPage")Integer currentPage,@RequestParam("pageSize")Integer pageSize){
        Page<Blog> blogPage=blogService.getArticleByBlogSortUid(uid,currentPage,pageSize);
        return new Result("success",new PageResult<Blog>(blogPage.getTotal(),blogPage.getResult()));
    }

    @GetMapping("/getBlogSortList")
    public Result getBlogSortList(){
        List<BlogSort>blogSortList=blogSortService.findAll();
        return new Result("success",blogSortList);
    }
}
